﻿namespace CloudNinja.Metering.Common
{
    using System;

    using CloudNinja.Metering.Authentication;
    using CloudNinja.Metering.Common.Logging;
    using CloudNinja.Metering.Data;

    using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling;
    using Microsoft.Practices.Unity;

    public class ContainerBootstrapper
    {
        public static void RegisterTypes(IUnityContainer container)
        {
            container.RegisterType<ILogger, AzureDiagnosticLogger>(new ContainerControlledLifetimeManager());

            var retryStrategy = new ExponentialBackoff(5, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1));

            var retryPolicy =
              new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy);


            var injectionConstructor = new InjectionConstructor(
                container.Resolve<ILogger>(),
                retryPolicy,
                retryPolicy,
                retryPolicy);

            container.RegisterType<IMeteringContext, MeteringContext>(
                new ContainerControlledLifetimeManager(), injectionConstructor);
        }
    }
}